package com.wc.alorithm_blue_bridge._贪心.Q1228;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.PriorityQueue;

/**
 * @Author congege
 * @Description
 * @Date Created in 2023/10/30-20:32
 */
public class Answer {
    public static void main(String[] args) {
        Input sc = new Input();
        int n = sc.nextInt();
        PriorityQueue<Long> queue = new PriorityQueue<>();
        while (n-- > 0) {
            queue.add((long) sc.nextInt());
        }
        long ans = 0;
        while (queue.size()!=1){
            long val1 = queue.poll();
            long val2 = queue.poll();
            ans += val1 + val2;
            queue.add(val1 + val2);
        }
        System.out.println(ans);
    }

    static class Input {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

        public int nextInt() {
            try {
                in.nextToken();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return (int) in.nval;
        }
    }
}
